//路由鉴权
import router from "@/router";

// 引入进度条
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

//引入大仓库

import {useLogin} from "@/stores/modules/user.ts";

//路由白名单
const whiteList=['/home','/hospital','/hospital/register','/hospital/message','/hospital/notice','/hospital/detail','/hospital/search']

// 全局路由守卫
// 前置路由
router.beforeEach((to,from,next)=>{
        nprogress.start()

    let Login = useLogin();
       //  token存在就放行
       if(Login.userInfo.token){
           next()
       }
       else {
         //   未登录但允许访问的路由放行
         if(whiteList.includes(to.path)){
                 next()
         }
         else {
             //   未登录但不允许访问的路由弹出登录框
             Login.dialogFormVisible=true
             nprogress.done()
         }
       }
})



//后置路由守卫
router.afterEach((to,from)=>{
        nprogress.done()
        document.title=`尚医通-${to.meta.title}`
})
